package com.xinlan.imageeditlibrary

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter

/**
 * @description tablayout+viewpager 公共类
 * @author 关忆北、
 * @time 2022/2/25 11:55 上午
 */
public class EditPagerAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm) {

    private var data: MutableList<String> = mutableListOf()
    var fragments = mutableListOf<Fragment>()

    override fun getItem(position: Int): Fragment {
        return fragments[position]
    }

    override fun getCount(): Int {
        return data.size.coerceAtLeast(0)
    }

    private fun getTitle(position: Int): String {
        return if (data.size > 0) data[position] else ""
    }


    fun setData(data: MutableList<String>) {
        this.data.clear()
        this.data = data
        notifyDataSetChanged()
    }

    override fun getPageTitle(position: Int): CharSequence? {
        return getTitle(position)
    }
}
